package com.concise.appapi.controller;

import com.concise.appapi.service.ArticleService;
import com.concise.appapi.service.model.RecommendTheArticleModel;
import com.concise.appapi.service.model.TheArticleListsModel;
import com.initialize.pub.pojo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: concise-blog
 * @description: 文章控制器
 * @author: Mr.Jane
 * @create: 2019-10-13 00:18
 **/
@CrossOrigin
@Api(tags = "文章API")
@RestController
@RequestMapping(value = "/article")
public class ArticleController {
    private final
    ArticleService articleService;

    public ArticleController(ArticleService articleService) {
        this.articleService = articleService;
    }

    /**
     * 这个暂时不用了
     * @return
     */
    @ApiOperation(value = "获取推荐的文章")
    @GetMapping("/recommended-articles")
    public Result getRecommendedArticles() {
        List<RecommendTheArticleModel> recommendTheArticleModels = articleService.getRecommendedArticles();
        return Result.success(recommendTheArticleModels);
    }

    @ApiOperation(value = "获取文章列表")
    @GetMapping("/the-article-lists")
    public Result getAListOfArticles() {
        List<TheArticleListsModel> theArticleListsModelList = articleService.getAListOfArticles();
        return Result.success(theArticleListsModelList);
    }


    @ApiOperation(value = "获取分类下文章列表")
    @GetMapping("/category-article-list/{cid}")
    public Result getAListOfArticlesUnderCategories(@PathVariable int cid) {
        List<TheArticleListsModel> theArticleListsModelList = articleService.getAListOfArticlesUnderCategories(cid);
        return Result.success(theArticleListsModelList);
    }


    @ApiOperation(value = "根据ID获取文章详情")
    @GetMapping("/article_details/{id}")
    public Result getArticleDetailsBasedOnId(@PathVariable int id) {
        return articleService.getArticleDetailsBasedOnId(id);
    }

}
